<template>
	<view class="content">
		<image class="logo" src="../../static/login.png" mode="widthFix"></image>
		<text class="title">房屋租赁登录</text>
		<u--form labelPosition="left" :model="formData" :rules="rules" ref="uForm">
			<u-form-item label="账号" prop="account" borderBottom ref="item1">
				<u--input v-model="formData.account" border="none" placeholder="请输入账号"></u--input>
			</u-form-item>
			<u-form-item label="密码" prop="password" borderBottom ref="item1">
				<u--input v-model="formData.password" border="none" placeholder="请输入密码" clearable password
					maxlength="16"></u--input>
			</u-form-item>
			<u-button type="primary" text="登录" @click="submit" class="btn"></u-button>
			<u-button text="注册" @click="register" class="btn"></u-button>
		</u--form>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				formData: {
					account: '',
					password: ''
				},
				rules: {
					'account': {
						type: 'string',
						required: true,
						message: '请填写账号',
						trigger: ['blur', 'change']
					},
					'password': {
						type: 'string',
						required: true,
						message: '请填写密码',
						trigger: ['blur', 'change']
					},
				},
			}
		},
		methods: {
	submit() {
		this.$refs.uForm.validate().then(r => {
			this.$api.account({
				password: this.formData.password,
				username: this.formData.account
			}).then(res => {
				// console.log(res)
				uni.setStorageSync('userinfo', res.resultObj.logininfo)
				uni.setStorageSync('user', res.resultObj.user)
				uni.setStorageSync('token', res.resultObj.token)
				uni.switchTab({
					url: '/pages/index/index'
				})
			})
		}).catch(errors => {
			console.log(errors)
			this.$refs.uToast.show({
				type: 'error',
				message: '请输入完整内容！',
	
			})
		})
	},
	register() {
		uni.navigateTo({
			url: '/pages/register/register'
		})
	}
		},
	}
</script>

<style lang="scss" scoped>
	.content {
		padding: 40rpx;
		display: flex;
		flex-direction: column;

		.logo {
			width: 200rpx;
			margin: 0 auto;
		}

		.title {
			font-size: 34rpx;
			font-weight: bold;
			margin-bottom: 40rpx;
			text-align: center;
		}

		.u-form {
			display: flex;
			flex-direction: column;
		}

		.u-form-item {
			margin-bottom: 20rpx;
		}

		.btn {
			margin-top: 20rpx;
		}
	}
</style>